﻿using MediatR;
using SmartTracking.ErrorCode;
using SmartTracking.Domain.EWE;
using SmartTracking.Infrastructure.Interfaces;
using AutoMapper;
using Yitter.IdGenerator;

namespace SmartTracking.ApiWrite.Applications.Commands.Ewemating
{
    /// <summary>
    /// 母羊配种
    /// </summary>
    public class DeleteEwematingCommandHandler : IRequestHandler<DeleteEwematingCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<Ewematings> eRep;
        private readonly IMapper mapper;

        public DeleteEwematingCommandHandler(IBaseRepository<Ewematings> eRep, IMapper mapper)
        {
            this.eRep = eRep;
            this.mapper = mapper;
        }

        public async Task<ApiResult<int>> Handle(DeleteEwematingCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int>result=new ApiResult<int>();
            result.Code = ApiEnum.删除成功;
            result.Message = "删除成功";

            var list =await eRep.GetByIdAsync(request.EwematingId);
            list.IsDeleted = true;
            await eRep.UpdateAsync(list);

            return await Task.FromResult(result);
        }
    }
}
